const {
  $util,
} = getApp();
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: $util.getImgUrl(),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (opts) {
    wx.setNavigationBarTitle({
      title: opts.barTitle && decodeURIComponent(opts.barTitle) || '考试中心',
    });
    this.setData(opts, () => {
      this.loadRecordDetail();
    });
  },
  loadRecordDetail() {
    $util.request({
      url: 'entry/wxapp/edu.exam.testhistory',
      data: {
        reviewid: this.data.paperid,
        id: this.data.recordid,
      },
      success: (res) => {
        this.setData(res.info);
        this.setData({
          wrong: res.info.testnum - res.info.grade,
          score: res.score,
          chance: res.testpaper.times,
        });
      },
    });
  },
  go(e) {
    let typ = e.currentTarget.dataset.type;
    let url = '/ws_party_const/pages/education/train/network/test/record';

    if (String(typ) === 'rightdata' && Number(this.data.grade) === 0) {
      wx.showToast({
        title: '没有答对题哦',
        icon: 'none',
      });
      return false;
    }

    if (String(typ) === 'errdata' && Number(this.data.wrong) === 0) {
      wx.showToast({
        title: '没有答错题哦',
        icon: 'none',
      });
      return false;
    }

    app.util.navigateTo(url, {
      id: this.data.paperid,
      recordid: this.data.recordid,
      typ: typ,
    });
  },
  goSortList() { // 查看排行榜
    let url =  `/ws_party_const/pages/education/train/network/test/sort`;
    getApp().util.navigateTo(url, {
      id: this.data.paperid,
      title: this.data.title,
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
});